import { BaseWindow } from "../../../../component/window/BaseWindow";
import { Language } from "../../../../../extend/language/Language";
import { ObjCreate } from "../../common/ObjCreate";
import { GTextFormat } from "../../../../common/GTextFormat";
import { FontUtil } from "../../../../common/font/FontUtil";
import { HTMLUtil } from "../../../../../com/gengine/utils/HTMLUtil";
import { SPetInfo } from "../../../../../Message/Game/SPetInfo";
import { PetUtil } from "../info/PetUtil";
import { GButton } from "../../../../../com/mui/controls/GButton";
import { Cache } from "../../../cache/Cache";
import { StringHelper } from "../../../../../com/gengine/utils/StringHelper";
import { MsgManager } from "../../../manager/MsgManager";
import { Dispatcher } from "../../../../mvc/core/Dispatcher";
import { DataEvent } from "../../../events/DataEvent";
import { EventName } from "../../../mvc/EventName";
import { GuideArrowManager } from "../../../manager/GuideArrowManager";
import { GTextInput } from "../../../../../com/mui/controls/GTextInput";
type int = number;
//class PetExtendAlertWindow
    
    export  class PetExtendAlertWindow extends BaseWindow
    {
        constructor()
        {
            super();
            if (PetExtendAlertWindow._instance) 
            {
                throw new Error("PetExtendAlertWindow单例");
            }
            this.init();
            return;
        }

        /* internal  */init(): void
        {
            this.setSize(300, 200);
            this.titleHeight = 28;
            this.title = Language.getString(54049);
            this._bg = ObjCreate.createBg(17, 39, 264, 128, this);
            this._tipTxt = ObjCreate.createTextField("", 0, 50, 300, 50, this, new GTextFormat(FontUtil.songtiName, 14, 11661311));
            this._tipTxt.autoSize = flash.text.TextFieldAutoSize.CENTER;
            this._tipTxt.multiline = true;
            this._inputTipTxt = ObjCreate.createTextField("", 0, 100, 300, 50, this, new GTextFormat(FontUtil.songtiName, 14, 11661311));
            this._inputTipTxt.multiline = true;
            this._inputTipTxt.htmlText = "<textFormat leading=\'5\'>" + HTMLUtil.addColor(Language.getString(54050), "#B1efff") + "</textFormat>";
            this._inputTipTxt.autoSize = flash.text.TextFieldAutoSize.CENTER;
            this._delInput = ObjCreate.createGTextInput(80, 140, 135, 20, this);
            this._delInput.maxChars = 6;
            this._delInput.restrict = "A-z";
            this._okBtn = ObjCreate.createGButton(Language.getString(54055), 60, 130, 70, 27, this);
            this._okBtn.name = "ok";
            this._cancelBtn = ObjCreate.createGButton(Language.getString(54052), 160, 130, 70, 27, this);
            this._cancelBtn.name = "cancel";
            this._okBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onBtnClickHandler);
            this._cancelBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onBtnClickHandler);
            return;
        }

        public PetExtendAlertWindow.get petInfo(): SPetInfo
        {
            return this._petInfo;
        }

        public set petInfo(arg1: SPetInfo)
        {
            this._petInfo = arg1;
            if (arg1) 
            {
                this._tip = Language.getStringByParam(54056, PetUtil.getPetName(arg1));
                this._tipTxt.htmlText = this._tip;
            }
            return;
        }

        /* internal  */onBtnClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            var loc2=null;
            var loc1=arg1.target as GButton;
            if (this._petInfo) 
            {
                if (loc1.name != "ok") 
                {
                    this.hide();
                }
                else 
                {
                    if (this._mode == PetExtendAlertWindow.ValidateMode && !Cache.instance.guide.guidePetMerge) 
                    {
                        loc2 = this._delInput.text.toLocaleLowerCase();
                        if (StringHelper.getCharLength(StringHelper.trim(loc2)) == 0) 
                        {
                            MsgManager.showRollTipsMsg(Language.getString(54054));
                            return;
                        }
                        if (loc2 != "delete") 
                        {
                            MsgManager.showRollTipsMsg(Language.getString(54054));
                            return;
                        }
                    }
                    Dispatcher.dispatchEvent(new DataEvent(EventName.PetExtend, {"petMainUid": this._mainPetInfo.uid, "petDeputyUid": this._petInfo.uid}));
                    this.hide();
                }
            }
            return;
        }

        public set mode(arg1: int)
        {
            this._mode = arg1;
            if (arg1 == PetExtendAlertWindow.NormalMode || Cache.instance.guide.guidePetMerge) 
            {
                this.setSize(300, 160);
                this._bg.height = 108;
                this._okBtn.y = 110;
                this._cancelBtn.y = 110;
                this._inputTipTxt.visible = false;
                this._delInput.visible = false;
            }
            else 
            {
                this.setSize(300, 220);
                this._bg.height = 168;
                this._okBtn.y = 170;
                this._cancelBtn.y = 170;
                this._inputTipTxt.visible = true;
                this._delInput.visible = true;
            }
            return;
        }

        public /* override */ hide(): void
        {
            super.hide();
            this._delInput.text = "";
            if (Cache.instance.guide.guidePetMerge) 
            {
                if (GuideArrowManager.guideArrow.parent == this) 
                {
                    GuideArrowManager.hideGuideArrow();
                }
                Dispatcher.dispatchEvent(new DataEvent(EventName.Guide_PetMergeAlert));
            }
            return;
        }

        public PetExtendAlertWindow.get mainPetInfo(): SPetInfo
        {
            return this._mainPetInfo;
        }

        public set mainPetInfo(arg1: SPetInfo)
        {
            this._mainPetInfo = arg1;
            return;
        }

        public guidePetMerge(): void
        {
            var loc1=GuideArrowManager.getGuideArrow(GuideArrowManager.Dir_L, null, 0);
            loc1.x = this._okBtn.x + this._okBtn.width + 10;
            loc1.y = this._okBtn.y + this._okBtn.height / 2;
            $addChild(loc1);
            return;
        }

        public static get instance(): PetExtendAlertWindow
        {
            if (PetExtendAlertWindow._instance == null) 
            {
                PetExtendAlertWindow._instance = new PetExtendAlertWindow();
            }
            return PetExtendAlertWindow._instance;
        }

        /* internal */ /* var */_mode: int;

        /* internal */ /* var */_bg: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_okBtn: GButton;

        /* internal */ /* var */_cancelBtn: GButton;

        /* internal */ /* var */_delInput: GTextInput;

        /* internal */ /* var */_tipTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_inputTipTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_delTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_mainPetInfo: SPetInfo;

        /* internal */ /* var */_petInfo: SPetInfo;

        /* internal */ /* var */_tip: string="";

        public static /* var */NormalMode: int=0;

        public static /* var */ValidateMode: int=1;

        /* internal */ static /* var */_instance: PetExtendAlertWindow;
    }

            PetExtendAlertWindow.NormalMode = 0;
            PetExtendAlertWindow.ValidateMode = 1;
        